<h1>Templates</h1>
<div class='yui-gc'>
    <div class='yui-u first'>
        <p>Below are all the templates located in pixel/views/admin/pages/templates.</p>
        <div style='border:1px solid #ccc;padding:2px'>
        <table cellpadding='5' cellspacing='1' class='at-table' width='100%'>
            <thead>
            <tr>
                <th>Human Name</th>
                <th>File Name</th>
                <th width='1%'>Delete</th>
            </tr></thead>
        <?php
            $oe = 1;
            foreach( $templates as $template_file_name => $template_human_name )
            {
                $oe = 1 - $oe;
                echo '<tr class="at-row'.$oe.'">';
                echo content_tag('td', $template_human_name);
                echo content_tag('td', link_to($template_file_name, 
                                                array('controller'=>'admin/pages' ,
                                                'action'=>'templates?template_name='.rawurlencode($template_file_name))                        
                                                )
                                );
                echo content_tag('td', form_tag('templates').
                                        hidden_field_tag('template_file', $template_file_name).
                                        hidden_field_tag('action','delete_template').
                                        submit_tag('delete',array('class'=>'submit_delete','confirm'=>'Are you sure you want to delete this template? It can not be undone, and might mess up your site.')).
                                       end_form_tag(),
                                       array('width'=>'1%'));
                echo '</tr>';
            }
        ?>
        </table>
        </div>
    </div>
    <div class='yui-u'>
        <h3>Add a new template</h3>
        <?php
        if (!is_writable($pages->template_dir)) {
            echo content_tag('p', 'The templates directory is not writable by the server. Until you change permissions on that folder you will not be able to add templates via this interface. FTP still works though.');
        } else {
        ?>
        <?php if(isset($errors)) { echo content_tag('div',$errors,array('class'=>'form_error'));} ?>
        <?php echo form_tag('templates',array('id'=>'add-template')) ?>
        <?php echo hidden_field_tag('action','add_template') ?>
        
        <label>Template human name <br><span style='font-size:xx-small; color:#666;font-style:italic'>(like My Subpage)</span></label>
        <?php echo text_field_tag('template_human_name','',array('class'=>'required', 'style'=>'width:90%')); ?>
        
        <label>Template file name <br><span style='font-size:xx-small; color:#666;font-style:italic'>(alphanumeric and underscores only without .php extension: my_subpage)</span></label>
        <?php echo text_field_tag('template_file_name','',array('class'=>'validate-alphascore', 'style'=>'width:90%')) ?>
        
        <label>Duplicate content from another template?</label>
        <p><?php echo check_box_tag('duplicate') ?> Yes from:
        <?php echo select_tag('duplicate_template', options_for_select($templates)); ?></p>
        
        <p><?php echo submit_tag('Create Template') ?></p>
        
        <?php echo end_form_tag(); ?>
        <?php echo validate_form('add-template') ?>
        
        <?php } ?>
    </div>
</div>




